<?php

/**
 * Created by PhpStorm.
 * User: xionggang
 * Date: 15-5-6
 * Time: 下午3:43
 */
class Tag extends Admin_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model("admin/tag_model");
    }

    /**
     * auto:xg
     * 标签列表
     */
    public function index()
    {
        $tagname = $this->input->get('tagname') ? $this->input->get('tagname') : '';

        $this->data['op'] = 'list';
        $this->data['tagname'] = $tagname;
        $this->data['tag_url'] = "";
        $this->data['list'] = $this->tag_model->getlist($tagname);
        $this->load->view('admin/tag', $this->data);
    }

    /**
     * auto：xg
     * 添加标签
     */
    public function edit()
    {
        $id = $this->input->get('id',true);
        if (!empty($id)) {
            $this->data['info'] = $this->tag_model->get_one_tag($id);
        }
        $this->data['op'] = 'edit';
        $this->load->view('admin/tag', $this->data);
    }

    /**
     * auto:xg
     * 提交标签信息
     */
    public function save()
    {
        if (isset($_POST) && !empty($_POST)) {
            $id = $this->input->post('id') ? $this->input->post('id') : '';
            $post_date['tagname'] = $this->input->post('tagname') ? $this->input->post('tagname') : '';
            $post_date['title'] = $this->input->post('title') ? $this->input->post('title') : '';
            $post_date['keywords'] = $this->input->post('keywords') ? $this->input->post('keywords') : '';
            $post_date['description'] = $this->input->post('description') ? $this->input->post('description') : '';

            $save_flag = $this->tag_model->save_tag($id, $post_date);
            if ($save_flag == 1) {
                cpmessage("操作成功", "/index.php?d=admin&c=tag");
            } else {
                cpmessage("操作失败", "/index.php?d=admin&c=tag");
            }

        }
    }
    /**
     * auto:xg
     * 删除标签
     */
    public function del(){
        $id = $this->input->get('id',true);
         if($id>0){
             $del_flag = $this->tag_model->del_tag($id);
             if ($del_flag == 1) {
                 cpmessage("操作成功", "/index.php?d=admin&c=tag");
             } else {
                 cpmessage("操作失败", "/index.php?d=admin&c=tag");
             }
         }
    }
}